set -e

MY_DIR=$(basename "$0" | sed 's/\.sh/.d/g')

bin=$(dirname "$0")
bin=$(
  cd "$bin"
  pwd
)

. meta-lib-static/env/.env
POSTGREST_SERVER_HOST=$(echo $POSTGREST_SERVER_NODES | cut -d, -f1)
POSTGREST_SERVER_PG_NODE=$(echo $POSTGREST_SERVER_PG_NODES | cut -d, -f1)
mkdir -p meta-lib-static/cache/conf

export POSTGREST_SERVER_PG_USERNAME POSTGREST_SERVER_PG_PASSWORD POSTGREST_SERVER_PG_NODE POSTGREST_SERVER_PG_DBNAME
export POSTGREST_SERVER_HOST POSTGREST_SERVER_PORT
cat meta-lib-static/conf/postgres.conf | envsubst > meta-lib-static/cache/conf/postgres.conf
${ACCESS_STATIC_DIR}/linux/postgrest-7.0.1 meta-lib-static/cache/conf/postgres.conf

